//2009/08/27 14:45:43
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class SquareDigitNumbers
{
public:
    int getNumber(int n)
    {
        int i;
        for (i=0; n>=0; i++)
            if (check(i)) n--;
        return i-1;
    }
    bool check(int n)
    {
        while (n > 0)
        {
            int a = n % 10;
            if (a!=0 && a!=1&& a!=4&& a!=9) return false;
            n /= 10;
        }
        return true;
    }
};
